A JavaServer Page (JSP) tag component (also referred to simply as a JSP tag) comprises a set of Java instructions that provide modular functionality that can be used by a JSP page. The use of JSP tags reduces the necessity to embed large amounts of Java code in a JSP page. A custom JSP tag library can be built of JSP tags providing related functions and provided to an end-user.
By using JSP tags it is not necessary to edit every JSP page when a change is desired. Instead, the JSP tag is changed and the change is manifested by all the JSP pages using the JSP tag.
The JSP tag architecture does not necessarily support tag reuse within another tag, however composite components can be built which include JSP tags within other JSP tags. The composite components enable the building of complex HTML elements. Reusing JSP tags within other JSP tags provides a common look and feel for other tags within the same library. When the look and feel needs to change, only one JSP tag has to change and all others (which use the tag) automatically benefit.
To use a JSP tag as a composite component, the logic which generates the HTML strings is pulled out of the doStartTag and/or doEndTag methods and placed in a public method that accepts required parameters to generate an HTML string. By creating this method, other tags are able to evoke this method and generate the same string as the tag itself, thereby making the JSP tag reusable within other JSP tags. Accordingly, JSP tags are modified by providing an externally invokable output rendering function that allows the JSP server engine to use the JSP tags, while also allowing a developer to create composite components that reference these JSP tags via calls to this added output function.
JavaServer Faces (JSF) is a server side user interface (UI) component framework for Java technology based Web applications. Using JSF, a client makes a request, the request goes across a network to a server, where the JSF adjacent framework builds up a user interface representation and renders back to the client in whatever markup language that is appropriate for the client. By way of JSF, a component developer can define the behavior of a component once, and provide multiple renderers, each of which defines a different way to render the component to the same or to different clients. Stated differently, when a page is rendered for a particular client type, whether the client type is an HTML browser running on a desktop or is a WML browser running on a wireless phone, a particular renderer is used for displaying the data maintained in a user interface components. Accordingly, the same user interface components can be used to display information on different client types using different protocols. The component associated with the tag selects the renderer to use. This is also true when using JATO which comprises an XML-based language that describes an XML to Java mapping that can convert XML to Java objects and back.
Referring now to FIG. 1, an example of the code used in a prior art composite component for JSF and JATO is shown. First, the doEndTag method of AddRemoveTag 60 is evoked. In this example all HTML generation code is located in the getHtmlString method, which allows tags to be used as composite components.). The getHtmlString method is evoked.
In this example, an HTML selectable list is also required. Instead of generating hard coded strings, an existing SelectableListTag tag class is used as a composite component to generate the HTML. A SelectableListTag tag is instantiated and attribute values are set. To obtain the required HTML, the getHTMLString method of SelectableListTag 62 is evoked. The result is not stored in the JSP buffer, but instead is stored in a local buffer (not shown). The stored strings are output to the JSP buffer 64 later on, after the getHTMLString method of AddRemoveTag returns it's result.
Adding results to a local buffer allows flexibility regarding when the result is appended to the output. This means that tags can be evoked in any order. In JSF, renderer output is written directly to the JSP buffer. This means that developers must be more selective about when to evoke a component renderer. Each JSF component renderer must be evoked in the order HTML is expected to be written to the JSP buffer.